package 包含min函数的栈;
import java.util.Stack;
public class Solution
{
    private Stack<Integer> minStack=new Stack<>();
    private Stack<Integer> stack=new Stack<>();

    public void push(int node)
    {
        //压入的时候，把最小的也压入辅助栈
        if (!stack.isEmpty())
        {

            if (minStack.peek()<node)
            {
                minStack.push(minStack.peek());
            }
            else
            {
                minStack.push(node);
            }
            stack.push(node);
        }
        else
        {
            stack.push(node);
            minStack.push(node);
        }

    }

    public void pop()
    {
        if (!stack.isEmpty()&&!minStack.isEmpty())
        {
            stack.pop();
            minStack.pop();
        }
    }

    public int top()
    {
        return stack.peek();
    }

    public int min()
    {
        return minStack.peek();
    }
}
